using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace NGNntpPlugIn
{
	/// <summary>
	/// Summary description for Configuration.
	/// </summary>
	public class Configuration : System.Windows.Forms.Form
	{
		private NntpConfig m_config;

		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TextBox tbEmail;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox tbName;
		private System.Windows.Forms.Button btnApply;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.Label lblMessage;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.CheckBox cbAlwaysPrompt;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.Button btnUpdate;
		private System.Windows.Forms.Label lblVersion;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Configuration()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.tbEmail = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.tbName = new System.Windows.Forms.TextBox();
			this.btnApply = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.lblMessage = new System.Windows.Forms.Label();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.cbAlwaysPrompt = new System.Windows.Forms.CheckBox();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.btnUpdate = new System.Windows.Forms.Button();
			this.lblVersion = new System.Windows.Forms.Label();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.tbEmail);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.tbName);
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(312, 80);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Your Information:";
			// 
			// tbEmail
			// 
			this.tbEmail.Location = new System.Drawing.Point(48, 48);
			this.tbEmail.Name = "tbEmail";
			this.tbEmail.Size = new System.Drawing.Size(256, 20);
			this.tbEmail.TabIndex = 3;
			this.tbEmail.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 15);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(40, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "Name:";
			this.label1.TextAlign = System.Drawing.ContentAlignment.TopRight;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(40, 23);
			this.label2.TabIndex = 2;
			this.label2.Text = "Email:";
			this.label2.TextAlign = System.Drawing.ContentAlignment.TopRight;
			// 
			// tbName
			// 
			this.tbName.Location = new System.Drawing.Point(48, 16);
			this.tbName.Name = "tbName";
			this.tbName.Size = new System.Drawing.Size(256, 20);
			this.tbName.TabIndex = 1;
			this.tbName.Text = "";
			// 
			// btnApply
			// 
			this.btnApply.Location = new System.Drawing.Point(160, 216);
			this.btnApply.Name = "btnApply";
			this.btnApply.TabIndex = 2;
			this.btnApply.Text = "Apply";
			this.btnApply.Click += new System.EventHandler(this.btnApply_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnCancel.Location = new System.Drawing.Point(240, 216);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 3;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// lblMessage
			// 
			this.lblMessage.ForeColor = System.Drawing.Color.Red;
			this.lblMessage.Location = new System.Drawing.Point(16, 216);
			this.lblMessage.Name = "lblMessage";
			this.lblMessage.Size = new System.Drawing.Size(136, 23);
			this.lblMessage.TabIndex = 4;
			this.lblMessage.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.cbAlwaysPrompt);
			this.groupBox2.Location = new System.Drawing.Point(8, 96);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(312, 48);
			this.groupBox2.TabIndex = 1;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Posting Options:";
			// 
			// cbAlwaysPrompt
			// 
			this.cbAlwaysPrompt.Location = new System.Drawing.Point(8, 16);
			this.cbAlwaysPrompt.Name = "cbAlwaysPrompt";
			this.cbAlwaysPrompt.Size = new System.Drawing.Size(296, 24);
			this.cbAlwaysPrompt.TabIndex = 0;
			this.cbAlwaysPrompt.Text = "Always prompt for newsgroup selection when replying.";
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.Add(this.lblVersion);
			this.groupBox3.Controls.Add(this.btnUpdate);
			this.groupBox3.Location = new System.Drawing.Point(8, 152);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(312, 48);
			this.groupBox3.TabIndex = 5;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "NNTP Plugin Information:";
			// 
			// btnUpdate
			// 
			this.btnUpdate.Location = new System.Drawing.Point(184, 16);
			this.btnUpdate.Name = "btnUpdate";
			this.btnUpdate.Size = new System.Drawing.Size(120, 23);
			this.btnUpdate.TabIndex = 0;
			this.btnUpdate.Text = "Check for Update";
			this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
			// 
			// lblVersion
			// 
			this.lblVersion.Location = new System.Drawing.Point(16, 16);
			this.lblVersion.Name = "lblVersion";
			this.lblVersion.Size = new System.Drawing.Size(168, 23);
			this.lblVersion.TabIndex = 1;
			this.lblVersion.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// Configuration
			// 
			this.AcceptButton = this.btnApply;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.btnCancel;
			this.ClientSize = new System.Drawing.Size(330, 248);
			this.Controls.Add(this.groupBox3);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.lblMessage);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnApply);
			this.Controls.Add(this.groupBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "Configuration";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "NNTP Configuration";
			this.Load += new System.EventHandler(this.Configuration_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void Configuration_Load(object sender, System.EventArgs e)
		{
			m_config = new NntpConfig();

			tbName.Text = m_config.Name;
			tbEmail.Text = m_config.Email;
			cbAlwaysPrompt.Checked = m_config.AlwaysPromptWhenReplying;

			lblVersion.Text = string.Format("Version {0}.{1}.{2}.{3}", new object[] {m_config.PluginVersion.Major, m_config.PluginVersion.Minor, m_config.PluginVersion.Build, m_config.PluginVersion.Revision});
		}

		private void btnApply_Click(object sender, System.EventArgs e)
		{
			try
			{
				m_config.SaveConfig(tbName.Text, tbEmail.Text, cbAlwaysPrompt.Checked);
				this.Close();
			}
			catch (ConfigException cex)
			{
				lblMessage.Text = cex.Message;
			}
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void btnUpdate_Click(object sender, System.EventArgs e)
		{
			m_config.CheckForUpdate(true);
		}

	}
}
